home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / System7 tools / Frontier / Frontier SDK 2.1 / Toolkits / Applet Toolkit / appletabout.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-11  |  3.9 KB  |  224 lines  |  [TEXT/KAHL]

  1.  
  2. /*© Copyright 1988-1992 UserLand Software, Inc.  All Rights Reserved.*/
  3.  
  4.  
  5. #include "appletinternal.h"
  6. #include "appletops.h"
  7. #include "appletquickdraw.h"
  8. #include "appletmain.h"
  9. #include "appletzoom.h"
  10. #include "appletabout.h"
  11.  
  12.  
  13. #ifdef MPWC
  14.  
  15. #include <toolutils.h>
  16. #include <osevents.h>
  17.  
  18. #endif
  19.  
  20.  
  21.  
  22. #define aboutlistnumber 128
  23.  
  24. WindowPtr aboutwindow = nil;
  25.  
  26.  
  27.  
  28.  
  29.  
  30. #define doline(x)\
  31.                                                                             \
  32.     MoveTo (r.left + (r.right - r.left - StringWidth (x)) / 2, linev);        \
  33.                                                                             \
  34.     DrawString (x);                                                            \
  35.                                                                             \
  36.     linev += lineinc;
  37.  
  38.  
  39. static void drawabout (WindowPtr w) {
  40.     
  41.     register short i;
  42.     register short linev = 24;
  43.     register short lineinc = 14;
  44.     bigstring lines [6];
  45.     Rect r;
  46.     
  47.     for (i = 0; i <= 5; i++)    
  48.         GetIndString (lines [i], aboutlistnumber, i + 1);
  49.     
  50.     r = (*w).portRect;
  51.     
  52.     InsetRect (&r, 4, 4);
  53.     
  54.     TextFont (systemFont);
  55.     
  56.     TextSize (12);
  57.     
  58.     doline (lines [0]);
  59.     
  60.     TextFont (geneva);
  61.     
  62.     TextSize (9);
  63.     
  64.     doline (lines [1]);
  65.     
  66.     linev += lineinc; /*skip a line*/
  67.     
  68.     doline (lines [2]);
  69.     
  70.     doline (lines [3]);
  71.     
  72.     MoveTo (r.left + 4, r.bottom - 6);
  73.     
  74.     DrawString (lines [4]);
  75.     
  76.     MoveTo (r.right - StringWidth (lines [5]) - 4, r.bottom - 6);
  77.     
  78.     DrawString (lines [5]);
  79.     } /*drawabout*/
  80.     
  81.  
  82. void openabout (Boolean flzoom) { /*can also be called to implement the splash window*/
  83.  
  84.     Rect r;
  85.     
  86.     SetRect (&r, 0, 0, 340, 120);
  87.     
  88.     pushmacport (aboutwindow = NewWindow (nil, &r, (ConstStr255Param)"\p", false, altDBoxProc, (WindowPtr) -1, false, 0));
  89.         
  90.     centerwindow ((DialogPtr) aboutwindow, quickdrawglobal (screenBits).bounds);
  91.     
  92.     if (flzoom)
  93.         zoomport (aboutwindow, true);
  94.     else
  95.         ShowWindow (aboutwindow);
  96.     
  97.     drawabout (aboutwindow);
  98.     } /*openabout*/
  99.     
  100.     
  101. void closeabout (Boolean flzoom) {
  102.  
  103.     if (aboutwindow != nil) {
  104.     
  105.         HideWindow (aboutwindow);
  106.         
  107.         if (flzoom)
  108.             zoomport (aboutwindow, false);
  109.         else
  110.             HideWindow (aboutwindow);
  111.         
  112.         DisposeWindow (aboutwindow);
  113.         
  114.         aboutwindow = nil;
  115.         
  116.         popmacport ();
  117.         }
  118.     } /*closeabout*/
  119.     
  120.     
  121. static boolean aboutwindowopen (void) {
  122.     
  123.     return (aboutwindow != nil);
  124.     } /*aboutwindowopen*/
  125.  
  126.  
  127. static boolean abouthandleevent (EventRecord ev, boolean *boxgoesaway) {
  128.  
  129.     /*
  130.     return true if the event is consumed, false if not.
  131.     
  132.     set boxgoesaway to true if the event should cause the about box to disappear.
  133.     */
  134.     
  135.     *boxgoesaway = false;
  136.     
  137.     switch (ev.what) {
  138.     
  139.         case keyDown: case autoKey: {
  140.         
  141.             register char ch = ev.message & charCodeMask;
  142.             
  143.             if ((ch == chreturn) || (ch == chenter)) {
  144.                 
  145.                 *boxgoesaway = true;
  146.                 
  147.                 return (true); /*event consumed*/
  148.                 }
  149.                 
  150.             break;
  151.             }
  152.             
  153.         case mouseDown:    {    
  154.             WindowPtr w;
  155.             
  156.             FindWindow (ev.where, &w);
  157.             
  158.             if (w != aboutwindow) /*event definitely not consumed*/
  159.                 return (false);
  160.                 
  161.             if (w == FrontWindow ())
  162.                 *boxgoesaway = true;
  163.             else
  164.                 SelectWindow (w);
  165.             
  166.             return (true); /*event consumed*/
  167.             }
  168.             
  169.         case updateEvt: {
  170.             register WindowPtr eventwindow = (WindowPtr) (ev.message);
  171.     
  172.             if (eventwindow != aboutwindow)
  173.                 return (false); /*event not consumed*/
  174.             
  175.             /*handle update, we might be using a screen saver*/
  176.             
  177.             pushmacport (eventwindow);
  178.             
  179.             BeginUpdate (eventwindow);
  180.             
  181.             drawabout (eventwindow);
  182.             
  183.             EndUpdate (eventwindow);
  184.             
  185.             popmacport ();
  186.                                 
  187.             return (true); /*event consumed, don't get rid of the about box*/
  188.             }
  189.             
  190.         case activateEvt:                                
  191.             return (true); /*event consumed, don't get rid of the about box*/
  192.         } /*switch*/
  193.     
  194.     return (false); /*event not consumed*/
  195.     } /*abouthandleevent*/
  196.  
  197.  
  198. void aboutcommand (void) {
  199.     
  200.     EventRecord ev;
  201.     boolean flexitabout = false;
  202.     
  203.     openabout (true);
  204.     
  205.     while (!flexitabout) {
  206.         
  207.         WaitNextEvent (everyEvent, &ev, 1, nil);
  208.         
  209.         if (!abouthandleevent (ev, &flexitabout)) { /*event not consumed by about box*/
  210.         
  211.             if (!maineventhandler (ev)) { /*user pressed cmd-period or Quit from file menu*/
  212.             
  213.                 flexitabout = true;
  214.                 }
  215.             }
  216.         } /*while*/
  217.     
  218.     closeabout (true);
  219.     } /*aboutcommand*/
  220.  
  221.  
  222.  
  223.  
  224.